<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
td {
	font-size: 13px
}
table.ttb{border-left:solid 1px #99bbe8;border-top: solid 1px #99bbe8;}
table.ttb td{word-break: break-all; word-wrap:break-word;vertical-align: top; padding-left:8px; border-right: solid 1px #99bbe8;border-bottom: solid 1px #99bbe8; line-height: 24px; font-size: 12px;}
.bg001{font-weight: bold; color: #333; background-color: #edf4fc}
</style>
	<script>
		$(function(){
			$('#tab').datagrid({
				title:'用户信息',
				iconCls:'icon-save',
				nowrap: false,
				striped: true,
				pageSize:20,
				pageList:[2,10,20,30,40,50,300],
				url:'/itmanager/yh/yhwhjson',
				remoteSort: false,
				idField:'id',
				columns:[
					[
						{field:'ck',checkbox:true},
						{field:'dlm',title:'用户名称',width:150},
						{field:'zsxm',title:'真实姓名',width:150},
						{field:'mc',title:'所属角色',width:150}
					]
				],
				fit:true,
				border:false,
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'1',
					text:'添加',
					disabled:true,
					iconCls:'icon-add',
					handler:function(){
						$('#czForm').form('clear');
						$('#tag').val('add');
						$('#jsid').val('3');
						$('#cz').dialog('open');
					}
				},'-',{
					id:'2',
					text:'修改',
					disabled:true,
					iconCls:'icon-edit',
					handler:function(){
						var record = $('#tab').datagrid("getSelections");
						if(record.length==1){
							$('#cz').dialog('open');
							$('#czForm').form('load','/itmanager/yh/yhwhcz?tag=find&id='+record[0].id);
							$('#tag').val('edit');
						}else{
							$.messager.alert('友情提示','<br/>只能选择一条记录进行修改！','error');
						}
					}
				},'-',{
					id:'3',
					text:'删除',
					disabled:true,
					iconCls:'icon-remove',
					handler:function(){
						var ids = [];
						var record = $('#tab').datagrid("getSelections");
						for(var i=0;i<record.length;i++){
							ids.push(record[i].id);
						}
						ids.join(",");
						$.ajax({
							 url:'/itmanager/yh/yhwhcz',
							 type:'post',
							 data:"ids="+ids,
							 success:function(data){
								 if(data == 'success'){
									 $.messager.alert('友情提示','<br/>删除成功！','right');
								 }else{
									 $.messager.alert('友情提示','<br/>删除失败！','error'); 
								 }
								 $('#tab').datagrid('reload');
							 },
							 error:function(data){
								 $.messager.alert('友情提示','<br/>修改失败！','error');
							 }
						 });
					}
				},'-',{
					id:'14',
					text:'查询密码',
					disabled:true,
					iconCls:'icon-save',
					handler:function(){
						 var rows = $('#tab').datagrid('getSelections');
						 if(rows.length == 1){
							 var row = rows[0];
							 $.ajax({
								 url:'${syspath}/itmanager/yh/yhwhcz?tag=find',
								 type:'get',
								 data:row,
								 dataType:'json',
								 success:function(data){
									 $('#cxmm').window({
										 title:'密码查询',
										 iconCls:'icon-friends',
										 width:200,
										 height:120,
										 minimizable:false,
										 maximizable:false,
										 modal: true
									 });
									 $('#tdYhm').text(data.dlm);
									 $('#tdMm').text(data.mm);
								 }
							 });
						 }else{
							 $.messager.alert('友情提示','<br/>只能选择一条记录进行查询！','error');
						 }
					}
				},'-',{
					id:'15',
					text:'密码重置',
					disabled:true,
					iconCls:'icon-undo',
					handler:function(){
						var rows = $('#tab').datagrid('getSelections');
						var ids = [];
						for(var i=0;i<rows.length;i++){
							ids.push(rows[i].id);
						}
						ids.join(",");
						$.ajax({
							type:'post',
							url:'/itmanager/yh/czmm',
							data:"ids="+ids,
							success:function(msg){
								 if(msg == "success"){
									 $.messager.alert('友情提示','<br/>操作成功，勾选用户密码重置为<font color=red>123456</font>！','right');
								 }else if(msg=="error"){
									 $.messager.alert('友情提示','<br/>操作出错！','error');
								 }
							}
							
						});
						
					}
				}]
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  $("#tab").datagrid("options");
					  $("#tab").datagrid("reload");
				   }
			  });
			 
			$('#cz').dialog({
				 title:'用户信息操作',
				 closed:true,
				 width:350,
				 height:210,
				 iconCls:'icon-edit',
				 closable:true,
				 border:false,
				 modal: true,
				 buttons:'#dlg-buttons'
			 });
			 
			 $('#dlm').validatebox({
				 required:true,
				 validType:'length[5,10]'
			 });
			 

			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
			 
		});
		
		var clsDlg = function(pid){
			$('#'+pid).dialog('close');
		}
		
		var submitForm = function(id){
			$('#'+id).form('submit',{
				url:'/itmanager/yh/yhwhcz',
				success:function(data){
					var tag = $('#tag').val();
					 $.messager.alert('友情提示','<br/>保存成功！','right');
					 $("#tab").datagrid("reload");
					 if(tag=='edit'){
						 $('#cz').dialog('close');
					 }
					 $('#czForm').form('clear');
					 $('#tag').val(tag);
				},
				onLoadError:function(){
					$.messager.alert('友情提示','<br/>保存失败！','error');
				},
				onSubmit:function(){
					var bool = $('#'+id).form('validate');
					if(!bool){
						return false;
					}
				}
			});
		}
	</script>
</head>
<body class="easyui-layout">
	<div id="center" region="center" border="false">
		<table id="tab"></table>
	</div>
	
	<div id="cz" style="padding:15px">
		<form id="czForm" method="post">
		    <input type="hidden" name="tag" id="tag" value="add"/>
		    <input type="hidden" id="id" name="id" style="width:150px"></input>
			<table>
				<tr>
					<td>用&nbsp;户&nbsp;名</td>
					<td><input id="dlm" name="dlm" style="width:150px"></input></td>
				</tr>
				<tr>
					<td>真实姓名</td>
					<td><input class="easyui-validatebox" required="true" id="zsxm" name="zsxm" style="width:150px"></input></td>
				</tr>
				<tr>
					<td>角&nbsp;&nbsp;&nbsp;&nbsp;色</td>
					<td>
					<select id="jsid" name="jsid" style="width:150px" class="easyui-validatebox" required="true">
						<c:forEach items="${rslist }" var="rs">
							<option value="${rs.id }">${rs.mc }</option>
						</c:forEach>
					</select></td>
				</tr>
			</table>
		</form>
		<div id="dlg-buttons">
			<a class="easyui-linkbutton" href="javascript:void(0)" onclick="submitForm('czForm')" id="btn-save"
				icon="icon-ok">保存</a> 
			<a class="easyui-linkbutton"  href="javascript:void(0)"
				onclick="clsDlg('cz')" id="btn-cancel" icon="icon-undo">取消</a>
		</div> 
	</div>
	
	<div id="cxmm" style="padding:15px">
		<table>
			<tr>
				<td>用户名</td>
				<td id="tdYhm"></td>
			</tr>
			<tr>
				<td>密&nbsp;&nbsp;码</td>
				<td id="tdMm"></td>
			</tr>
		</table> 
	</div>
</body>
</html>